package world.square;

import java.math.BigDecimal;

import be.kuleuven.cs.som.annotate.Raw;

import world.edges.Border;
import world.edges.Wall;
import world.placement.Direction;

/**
 * Class representing a rocky square. 
 * A rocky square can't contain objects and has a wall in each direction.
 * 
 * @author Frederic Mes, Wim Marynissen
 * @version 1.0
 */
public class Rock extends Square{

	/**
     * Create a new rock square.
     * 
     * @effect 	This new rock is initialized.
     *          | super(Temperature.ZERO, BigDecimal.ZERO, Direction.values())
     */
    public Rock() throws IllegalArgumentException {
            super(Temperature.ZERO, BigDecimal.ZERO, Direction.values());
    }

    /**
	 * Test if the square can have a certain border.
	 * @param 	border
	 * 			The border to check.
	 * @return	False if the border is not a wall.
	 * 			| if(border != null)
	 * 			| 	if( !isTerminated() && !(border.getBorderElement() instanceof Wall) )
	 * 			| 		then result == false
	 * @effect	Test if the rock can have the specified border, considering the rock as a square.
	 * 			| super.canHaveAsBorder(border)
	 */
    @Raw
    @Override
    public boolean canHaveAsBorder(Border border){
    	if(border != null)
            if( !isTerminated() && !(border.getBorderElement() instanceof Wall) )
                    return false;
        return super.canHaveAsBorder(border);
    }
    
    /**
	 * Test if this rock has a proper border in the specified direction.
	 * @param 	direction
	 * 			The direction in which to verify the border
	 * @return	False if the border is non effective.
	 * 			| if(getBorder(direction) == null)
	 * 			| 	then result == false
	 * @return	True if the rock has been terminated.
	 * 			| if(this.isTerminated())
	 * 			| 	then result == true
	 * @return	The border must be a wall, and must reference back to this rock.
	 * 			| result == ((getBorder(direction).getSquare() == this)
	 * 			|		&& (getBorder(direction).getBorderElement() instanceof Wall))
	 */
    @Override
    public boolean hasProperBorder(Direction direction){
    	if(this.isTerminated())
    		return true;
    	if(getBorder(direction) == null)
    		return false;
		return ((getBorder(direction).getSquare() == this)
				&& (getBorder(direction).getBorderElement() instanceof Wall));
		
	}
    
    /**
	 * @param	humidity
	 * 			The humidity to check
	 * @return	The humidity must be zero.
	 * 			| result == (humidity.compareTo(new BigDecimal("0")) == 0)
	 */
	public static boolean isValidHumidity(BigDecimal humidity){
		return (humidity.compareTo(new BigDecimal("0")) == 0);
	}
    
    /**
	 * @param 	direction
	 * 			The direction in which to check for possibility of removal.
	 * @return	Always false.
	 * 			| result == false
	 */
    @Override
    public boolean canRemoveBorderInDirection(Direction direction){
    	return false;
    }
    
    /**
	 * @param 	directions
	 * 			The directions in which to remove borders.
	 * @throws	UnsupportedOperationException
	 * 			Borders can't be removed from a rock.
	 */
    @Override
    public void removeBorders(Direction... directions) throws UnsupportedOperationException{
    	throw new UnsupportedOperationException("A rock's border can't be deleted.");
    }
    /**
	 * @param 	direction
	 * 			The direction in which to check for possibility of removal.
	 * @throws	UnsupportedOperationException
	 * 			A rock can't be merged with another square.
	 */
    @Override
    public void mergeWith (Square square, Direction Direction) throws UnsupportedOperationException{
        throw new UnsupportedOperationException("Merging with rocks is impossible.");
    }
    
    /**
     * Get the maximum number of doors.
     */
    @Override
	public int maxNbDoors(){
		return 0;
	}
    
}
